﻿using System;

namespace Dotnet.Utils.Utility.ObjectExtensions.Number
{
    public static class IntExtensions
    {
        /// <summary>
        /// 转换成字节数组
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static byte[] GetBytes(this int value)
        {
            return BitConverter.GetBytes(value);
        }

        /// <summary>
        /// 随机数
        /// </summary>
        private static void Random()
        {
            // 随机数
            Random ran = new Random();
            Console.WriteLine(ran.Next(999));
            Console.WriteLine(ran.Next(100, 999));

            //获取200个随机数
            var ran2 = System.Security.Cryptography.RandomNumberGenerator.Create();
            byte[] bytes = new byte[200];
            ran2.GetBytes(bytes);
            foreach (var b in bytes)
            {
                Console.WriteLine(b);
            }

            //获取200个随机数 .net 6 +
            var newran = System.Security.Cryptography.RandomNumberGenerator.GetBytes(200);
            foreach (var b in newran)
            {
                Console.WriteLine(b);
            }
        }
    }
}